package com.pengtu.entity.app;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.pengtu.entity.IdEntity;

@Entity
@Table(name = "T_PROJ_USER_QUALIFICATION")
public class UserQualification extends IdEntity {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;

	private User user;
	private String technicalTitle;
	private String title;
	private String code;
	private String certificate;
	private Date certificateDate;
	private String undertake;
	private String qualificationfile; // 附件
	private String remark;
	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			}); // 附件

	@ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
	@JoinColumn(name = "USERID")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "TECHNICALTITLE")
	public String getTechnicalTitle() {
		return technicalTitle;
	}

	public void setTechnicalTitle(String technicalTitle) {
		this.technicalTitle = technicalTitle;
	}

	@Column(name = "TITLE")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "CODE")
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "CERTIFICATE")
	public String getCertificate() {
		return certificate;
	}

	public void setCertificate(String certificate) {
		this.certificate = certificate;
	}

	@Column(name = "CERTIFICATEDATE")
	@Temporal(TemporalType.DATE)
	public Date getCertificateDate() {
		return certificateDate;
	}

	public void setCertificateDate(Date certificateDate) {
		this.certificateDate = certificateDate;
	}

	@Column(name = "UNDERTAKE")
	public String getUndertake() {
		return undertake;
	}

	public void setUndertake(String undertake) {
		this.undertake = undertake;
	}

	@Column(name = "QUALIFICATIONFILE")
	public String getQualificationfile() {
		return qualificationfile;
	}

	public void setQualificationfile(String qualificationfile) {
		this.qualificationfile = qualificationfile;
	}

	@Column(name = "REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}

	public void setAttachmentSet(Set<Attachment> attachmentSet) {
		this.attachmentSet = attachmentSet;
	}

	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}

}
